package cn.com.dcsgo;

/**
 * 音节
 *
 * @author Dcsgo
 * @since 2025/2/17 14:07
 */

public class Syllable {
    /**
     * 唱名
     */
    private final String name;
    /**
     * 简谱
     */
    private final int number;
    /**
     * 音名
     */
    private final char pitchName;
    /**
     * 最大音节数(0除外)
     */
    public static final int MAX_SYLLABLE_NUMBER = 7;
    /**
     * 所有音节的唱名
     */
    private static final String[] names = {" ", "do", "re", "mi", "fa", "sol", "la", "si"};
    /**
     * 所有音节的音名
     */
    private static final char[] pitchNames = {' ', 'C', 'D', 'E', 'F', 'G', 'A', 'B'};

    public Syllable(int number) {
        if (number < 0 || number > MAX_SYLLABLE_NUMBER) {
            throw new IllegalArgumentException("number: " + number + "小于0或大于" + MAX_SYLLABLE_NUMBER);
        }
        this.number = number;
        this.name = names[number];
        this.pitchName = pitchNames[number];
    }

    public String getName() {
        return name;
    }

    public int getNumber() {
        return number;
    }

    public char getPitchName() {
        return pitchName;
    }

    @Override
    public String toString() {
        return name;
    }
}
